#coding=utf-8
from haystack import indexes
from blog import models


# 注意格式（模块类名+Index）
class BlogIndex(indexes.SearchIndex,indexes.Indexable):
    text = indexes.CharField(document=True,use_template=True)

    # 给title,content设置索引
    title = indexes.NgramField(model_attr="title")
    content = indexes.NgramField(model_attr="content")

    def get_model(self):
        return models.Post

    def index_queryset(self, using=None):
        return self.get_model().objects.order_by('-created')